/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Core.CoreManager;
import DataAccess.NgonNgu;
import DataAccess.NguoiDung;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author My PC
 */
public class NguoiDungController extends CoreManager<NguoiDung> {
    private String[] columnNames = {"Mã người dùng","Tên người dùng","Mật khẩu","Quyền"};
    public NguoiDungController()
    { super();
    GetAllData("NguoiDung");
    }
    @Override
    public void SetcolumnNames()
    {
        super.columnNames=columnNames;
    }
    public void showData(JTable table)
    {
        GetAllData("NguoiDung");
        DefaultTableModel tableModel=new DefaultTableModel(columnNames, 0);
        table.setModel(tableModel);
       // int no=1;
        for(Object o: super.list)
        {
            NguoiDung tg=(NguoiDung)o;
            Vector oneRow=new Vector();
            oneRow.add(tg.getNguoiDungId());
            oneRow.add(tg.getTenNguoiDung());
            tableModel.addRow(oneRow);
          //  System.out.println(tableModel.);
        }
    }
    public NguoiDung getNgonNguByIndex(int index)
    {
        return (NguoiDung)list.get(index);
    }
    public NguoiDung getNguoiDung(String _us,String _pass)
    {
        NguoiDung nguoidung=new NguoiDung();
        nguoidung.setTenNguoiDung("sa");
        nguoidung.setMatKhau("sa");
        nguoidung.setQuyen(0);
        //for(Object us : list)
            for(int i=0;i<list.size();i++)
        {
            NguoiDung nd=(NguoiDung) list.get(i);//(NguoiDung)us;
            if(nd.getTenNguoiDung()==_us && nd.getMatKhau()==_pass)
            {
                return nd;
                //break;
            }
        }
        return nguoidung;
    }
    
      public int GetLastID()
    {
        if(list.size()!=0)
        return ((NguoiDung)this.list.get(list.size()-1)).getNguoiDungId();
        else return 0;
        
    }
}

